package org.example.demo.dao;

import org.example.demo.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @ClassName: Fsk App
 * @Copyright: com.fsk
 * @Version: 1.0.0
 * @Author: chenming2
 * @UpdateTime: 2/27/2022
 * @Describe: XXXXXXX.
 */
@Repository
public class BookDaoImpl implements BookDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void add(Book book) {
        String sql = "insert into book values (?, ?, ?)";
        int update = jdbcTemplate.update(sql, book.getId(), book.getName(), book.getAuthor());
        System.out.println(update);
    }

    @Override
    public void update(Book book) {
        String sql = "update book set name = ? where id = ?";
        int update = jdbcTemplate.update(sql, book.getName(), book.getId());
        System.out.println(update);
    }
}
